<?php
// +----------------------------------------------------------------------
// | CloudSInk [ 我们依旧可以抱着所有幻想,继续走下去 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2022 http://www.cloudsink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 云影 <3502914536@qq.com>
// +----------------------------------------------------------------------
include("function.php");
$action = $_GET['action'];
switch ($action) {
    case 'submit':
        $uid = $_POST['uid'];
        if (empty($uid)) exit(json_encode(['status' => -1, 'message' => '请输入UID！']));
        $token = getToken($uid)['token'];
        $number = $_POST['number'];
        $number_topic = $_POST['number_topic'];
        if (empty($token)) exit(json_encode(['status' => -4, 'message' => '获取相关信息失败,请稍后再试！','data'=>getToken($uid)]));
        if ($number > 10) exit(json_encode(['status' => -2, 'message' => '单次刷取数量不可大于10']));
        if ($number_topic > 10) exit(json_encode(['status' => -2, 'message' => '单次刷取数量不可大于10']));
        $success = 0;
        $error = 0;
        for ($i = 0; $i < $number; $i++) {
            $url = 'https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=1&rank_time=0&rank_role=1&skin=1&t='.$token.'&content-type=application%2Fjson&User-Agent=Mozilla%2F5.0%20(iPhone%3B%20CPU%20iPhone%20OS%2015_6%20like%20Mac%20OS%20X)%20AppleWebKit%2F605.1.15%20(KHTML%2C%20like%20Gecko)%20Mobile%2F15E148%20MicroMessenger%2F8.0.28(0x18001c26)%20NetType%2FWIFI%20Language%2Fzh_CN';
            $data = json_decode(getCurl($url), true);
            $game_over = $data;
            if ($data['err_code']==0) {
                $success = $success + 1;
            } else {
                $error = $error + 1;
            }
        }
        $success_topic = 0;
        $error_topic = 0;
        for ($i = 0; $i < $number_topic; $i++) {
            $url = 'https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=1&rank_time=0&rank_role=1&skin=1&t=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTQ2MDk0OTYsIm5iZiI6MTY2MzUwNzI5NiwiaWF0IjoxNjYzNTA1NDk2LCJqdGkiOiJDTTpjYXRfbWF0Y2g6bHQxMjM0NTYiLCJvcGVuX2lkIjoiIiwidWlkIjo4NzQ0OTc1LCJkZWJ1ZyI6IiIsImxhbmciOiIifQ.tYJUUQVdnelxwEAy1FdZgNUXz0EgRyNqPQxyT2-CMiA&content-type=application%2Fjson&User-Agent=Mozilla%2F5.0%20(iPhone%3B%20CPU%20iPhone%20OS%2015_6%20like%20Mac%20OS%20X)%20AppleWebKit%2F605.1.15%20(KHTML%2C%20like%20Gecko)%20Mobile%2F15E148%20MicroMessenger%2F8.0.28(0x18001c26)%20NetType%2FWIFI%20Language%2Fzh_CN';
            $data = json_decode(getCurl($url), true);
            if ($data['err_code']==0) {
                $success_topic = $success_topic + 1;
            } else {
                $error_topic = $error_topic + 1;
            }
        }
        exit(json_encode(['status' => 1, 'message' => '数据统计:<br/>通关次数<br/>成功' . $success . '次  失败：' . $error . '次<br/>话题排行榜:<br/>成功' . $success_topic . '次  失败：' . $error_topic . '次', 'data' => $data,'game_over'=>$game_over,'token'=>$token]));
    case 'token'://提取Token接口
        $uid = $_POST['uid'];
        if (empty($uid)) exit(json_encode(['status' => -1, 'message' => '请输入UID！']));
        $token = getToken($uid)['token'];
        if (isset($token)) {
            exit(json_encode(['status' => 1, 'message' => '获取Token成功！', 'token' => $token]));
        } else {
            exit(json_encode(['status' => -4, 'message' => '获取相关信息失败,请稍后再试！']));
        }
    case 'rank_info'://获取全网用户通关信息接口
        $token = $_GET['token'];
        if (empty($token)) exit(json_encode(['status' => -4, 'message' => '请输入Token！']));
        $url = 'https://cat-match.easygame2021.com/sheep/v1/game/rank_info_byte?isByte=true';
        $data = getCurl($url, null, $token);
        exit($data);
    case 'user_sink'://更新用户皮肤接口
        $uid = $_GET['uid'];
        $token = getToken($uid)['token'];
        if (empty($token)) exit(json_encode(['status' => -4, 'message' => '请输入Token！']));
        if (empty($sink)) exit(json_encode(['status' => -4, 'message' => '请输入Sink代码！']));
        $url = 'https://cat-match.easygame2021.com/sheep/v1/game/update_user_skin?skin=' . $sink;
        $data = getCurl($url, null, $token);
        exit($data);
    case 'topic_game': //刷取话题次数
        $uid = $_GET['uid'];
        $number = $_GET['number'];
        $token = getToken($uid)['token'];
        $url = 'https://cat-match.easygame2021.com/sheep/v1/game/topic_game_over?rank_score=1&rank_state=1&rank_time=20&rank_role=1&skin=1';
        $data = getCurl($url, null, $token);
        for ($i = 0; $i < $number; $i++) {
            $data = json_decode(getCurl($url), true);
            if ($data['err_code']) {
                $success = $success + 1;
            } else {
                $error = $error + 1;
            }
        }
        exit(json_encode(['status' => 1, 'message' => '数据统计:<br/>成功刷取' . $success . '次<br/>失败：' . $error . '次', 'data' => $data,'token'=>$token]));
    default:
        exit(json_encode(['status' => 1001, 'message' => 'Empty Action!']));
}